<%-- 
    Document   : enregistrer
    Created on : Dec 6, 2012, 2:55:47 PM
    Author     : etu17691
--%>

<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<fmt:setBundle basename="packageLangue.lang" scope="session"/>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<c:set var="pagename" scope="request" value="enregistrer.jsp"/>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<jsp:include page="header.jsp"></jsp:include>
    <div id="content">
        <div id="top">
                <h1><fmt:message key="Inscription"/></h1>
        </div>
        <div id="milieu">
            <div id="texte">   
                <p><fmt:message key="Description_Inscription"/></p>
                <form action="ServletAddUser" onsubmit="return testChamps()" method="post" id="form1">
                    <table cellspacing="5" width="100%">
                        <tr>
                            <td colspan="4"><h3><fmt:message key="Info_Perso"/></h3></td>
                        </tr>
                        <tr>
                            <td align=right><fmt:message key="Nom"/></td>
                            <td><input type="text" name="nom" size="30" style="float:left;"><div id="0"></div></td>
                            <td align=right><fmt:message key="Prenom"/></td>
                            <td><input type="text" name="prenom" size="30" style="float:left;"><div id="1"></div></td>
                        </tr>
                        <tr>
                            <td align="right"><fmt:message key="Adresse"/></td>
                            <td><input type="text" name="adresse" size="30" style="float:left;"><div id="2"></div></td>
                            <td align="right"><fmt:message key="Cp"/></td>
                            <td><input type="text" name="codePostal" size="30" style="float:left;"><div id="3"></div></td>
                        </tr>
                        <tr>
                            <td align="right"><fmt:message key="Ville"/></td>
                            <td><input type="text" name="ville" size="30" style="float:left;"><div id="4"></div></td>
                            <td align="right"><fmt:message key="Mail"/></td>
                            <td><input type="text" name="email" size="30" style="float:left;"><div id="5"></div></td>
                        </tr>
                        <tr>
                            <td align="right"><fmt:message key="Tel"/></td>
                            <td><input type="text" name="tel" size="30"></td>
                        </tr>
                        <tr>    
                            <td align="right"><fmt:message key="Mdp"/></td>
                            <td><input type="password" name="mdp" size="30" style="float:left;"><div id="7"></div></td>
                        </tr>
                        <tr>    
                            <td align="right"><fmt:message key="Conf"/></td>
                            <td><input type="password" name="mdpbis" size="30" style="float:left;"><div id="8"></div></td>
                        </tr>
                        <tr>
                            <td></td>
                        </tr>
                        <tr>
                            <td colspan="4" align="center"><input type="submit" name="envoyer" value="<fmt:message key="Envoi"/>" class="bouton"> <input type="reset" name="reset" value="<fmt:message key="Retab"/>" onclick="effacerChamps()"/></td>
                        </tr>
                        <tr>
                            <td colspan="4" align="center"><fmt:message key="Obligatoire"/></td>
                        </tr>
                    </table>
                </form>
            </div>  
        </div>
        <div id="bottom"></div>
    </div>
<jsp:include page="footer.jsp"></jsp:include>

<script>
    code = "<img src = \"img/attention.jpg\" style=\"border:0;\"/>";
    function testChamps()
    {
        frm = document.forms['form1'];
        valide = true;
        
        if(frm.elements[0].value != "")
            document.getElementById(0).innerHTML = "";
        else
        {
            document.getElementById(0).innerHTML = code;
            valide = false;
        }

        if(document.forms['form1'].elements[1].value != "")
            document.getElementById(1).innerHTML = "";
        else
        {
                document.getElementById(1).innerHTML = code;
                valide = false;
        }

        if(document.forms['form1'].elements[2].value != "")
            document.getElementById(2).innerHTML = "";
        else
        {
            document.getElementById(2).innerHTML = code;
            valide = false;
        }

        if(isNaN(parseInt(document.forms['form1'].elements[3].value)) || parseInt(document.forms['form1'].elements[3].value) <= 0 || parseInt(document.forms['form1'].elements[3].value) > 99999)
        {    
            document.getElementById(3).innerHTML = code;
            valide = false;
        }
        else
            document.getElementById(3).innerHTML = "";

        if(document.forms['form1'].elements[4].value != "")
            document.getElementById(4).innerHTML = "";
        else
        {
            document.getElementById(4).innerHTML = code;
            valide = false;
        }

        if(bonmail(document.forms['form1'].elements[5].value))
            document.getElementById(5).innerHTML = "";
        else
        {
            document.getElementById(5).innerHTML = code;
            valide = false;
        }

        if(document.forms['form1'].elements[7].value != "")
            document.getElementById(7).innerHTML = "";
        else
        {
            document.getElementById(7).innerHTML = code;
            valide = false;
        }

        if(document.forms['form1'].elements[8].value != "")
            document.getElementById(8).innerHTML = "";
        else
        {
            document.getElementById(8).innerHTML = code;
            valide = false;
        }
        
        if(document.forms['form1'].elements[8].value == document.forms['form1'].elements[7].value)
        {
            document.getElementById(8).innerHTML = "";
            if(frm.elements[8].value == "")
                document.getElementById(8).innerHTML = code;
        }
        else
        {
            document.getElementById(8).innerHTML = code;
            valide = false;
        }
        return valide;
    }
	
    function bonmail(mailteste)
    {
        var reg = new RegExp('^[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*@[a-z0-9]+([_|\.|-]{1}[a-z0-9]+)*[\.]{1}[a-z]{2,6}$', 'i');
        return(reg.test(mailteste));
    }
    
    function effacerChamps()
    {
        for(i=0;i<9;i++)
        {
            if(i==6)
                i++;
            document.getElementById(i).innerHTML = "";
        }
    }
</script>